#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
struct node
{
    int index;
    int ret;
}row[N], col[N];
int m, n, k, l, d;
bool cmp1(node& x1, node& x2)
{
    return x1.ret > x2.ret;
}
bool cmp2(node& x1, node& x2)
{
    return x1.index < x2.index;
}
int main()
{
    cin >> m >> n >> k >> l >> d;
    for (int i = 1; i <= m; i++) row[i].index = i;
    for (int i = 1; i <= n; i++) col[i].index = i;
    while (d--)
    {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if (x1 == x2)
        {
            col[min(y1, y2)].ret++;
        }
        else
        {
            row[min(x1, x2)].ret++;
        }
    }
    sort(row + 1, row + m + 1, cmp1);
    sort(col + 1, col + n + 1, cmp1);
    sort(row + 1, row + k + 1, cmp2);
    sort(col + 1, col + l + 1, cmp2);
    for (int i = 1; i <= k; i++)
    {
        cout << row[i].index << ' ';
    }
    cout << endl;
    for (int i = 1; i <= l; i++)
    {
        cout << col[i].index << ' ';
    }
    return 0;
}